package com.StarStudio;

import com.StarStudio.MQTT.Config.MqttConfig;
import com.StarStudio.MQTT.EmqClient;
import com.StarStudio.MQTT.QosEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class Demo1Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);
    }
/*
    @Autowired
    private EmqClient emqClient;

    @Autowired
    private MqttConfig mqttConfig;

    @PostConstruct
    public void init(){
        //连接服务端
        emqClient.connect(mqttConfig.getUsername(), mqttConfig.getPassword());
        //订阅一个主题
        emqClient.subscribe("testtopic/#", QosEnum.Qos2);
        //开启一个新的线程，每隔3秒向主题testtopic/123发布消息
        new Thread(()->{
            while (true){
                emqClient.publish("testtopic/123","[publish msg:" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) +"]",QosEnum.Qos2,false);
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
*/
}
